// GradeController.java 控制器
package com.example.studentmanagement2.controller;

import com.example.studentmanagement2.dto.GradeDetail;
import com.example.studentmanagement2.model.Grade;
import com.example.studentmanagement2.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/grades")
public class GradeController {
    private final GradeService gradeService;

    @Autowired
    public GradeController(GradeService gradeService) {
        this.gradeService = gradeService;
    }

    @PostMapping
    public ResponseEntity<Grade> recordGrade(@RequestBody Grade grade) {
        return ResponseEntity.ok(gradeService.recordGrade(grade));
    }
    @GetMapping("/student/{studentId}")
    public ResponseEntity<List<GradeDetail>> getGradesByStudent(@PathVariable String studentId) {
        return ResponseEntity.ok(gradeService.getGradeDetails(studentId));
    }

    @GetMapping("/course/{courseId}")
    public ResponseEntity<List<GradeDetail>> getGradesByCourse(@PathVariable String courseId) {
        return ResponseEntity.ok(gradeService.getGradesByCourse(courseId));
    }
}